use std::{
    fs::File,
    io::{BufRead, BufReader},
};
use tracing::Level;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, filter};

pub fn read_url_list() -> Vec<String> {
    let file = File::open("data/images.txt").unwrap();
    let reader = BufReader::new(file);
    let mut lines = Vec::new();

    for line in reader.lines() {
        let line = line.unwrap();
        lines.push(line);
    }
    lines
}

pub fn open_debug() {
    if std::env::var_os("RUST_LOG").is_none() {
        std::env::set_var("RUST_LOG", "tower_http=debug;middleware=debug");
    }
    let filter = filter::Targets::new()
        .with_target("tower_http::trace::on_response", Level::TRACE)
        // .with_target("tower_http::trace::on_request", Level::TRACE)
        .with_target("tower_http::trace::make_span", Level::DEBUG)
        .with_default(Level::INFO);
    let tracing_layer = tracing_subscriber::fmt::layer();
    tracing_subscriber::registry()
        .with(tracing_layer)
        .with(filter)
        .init();
}
